package cn.king.springframework.beans.demo;

import cn.king.springframework.beans.factory.BeanFactory;
import cn.king.springframework.beans.factory.config.BeanDefinition;
import cn.king.springframework.beans.factory.support.DefaultListableBeanFactory;

public class App {
    public static void main(String[] args) {
        //1 创建工厂
        BeanFactory beanFactory = new DefaultListableBeanFactory();
        //2 注册bean
        BeanDefinition beanDefinition = new BeanDefinition(UserService.class);

        ((DefaultListableBeanFactory) beanFactory).registerBeanDefinition("userService",beanDefinition);
        //3 获取bean
        UserService userService = (UserService) beanFactory.getBean("userService");
        userService.queryUserInfo();

        // 4.第二次获取 bean from Singleton
        UserService userService_singleton = (UserService) beanFactory.getBean("userService");
        userService_singleton.queryUserInfo();
    }
}
